﻿Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Net
Imports System.Collections.Generic

Public Class nsWebClient
  Inherits WebClient
  Private _cookieContainer As CookieContainer
  Private _ua As String

  Public Property CookieContainer() As CookieContainer
    Get
      Return _cookieContainer
    End Get
    Set(ByVal value As CookieContainer)
      _cookieContainer = value
    End Set
  End Property

  Public Property UA() As String
    Get
      Return _ua
    End Get
    Set(ByVal value As String)
      _ua = value
    End Set
  End Property

  Protected Overrides Function GetWebRequest(ByVal address As System.Uri) As System.Net.WebRequest
    Dim myRequest As WebRequest = MyBase.GetWebRequest(address)

    If TypeOf myRequest Is HttpWebRequest Then
      DirectCast(myRequest, HttpWebRequest).CookieContainer = _cookieContainer
      DirectCast(myRequest, HttpWebRequest).UserAgent = _ua
    End If
    Return myRequest
  End Function

  Public Sub New()
    _cookieContainer = New CookieContainer
    _ua = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727)"
  End Sub

End Class
